package com.chap1;

import com.chap1.tools.SleepTools;

/**
 * <p>
 * <code>TestIntegerSyn</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-03-24 15:45
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class TestIntegerSyn {
    public static void main(String[] args) {
        Worker worker = new Worker(1);
        for (int i = 0; i < 5; i++) {
            new Thread(worker).start();
        }
    }
    private static class Worker implements Runnable{
        private Integer i;
        private Object o = new Object();

        public Worker(Integer i) {
            this.i = i;
        }

        @Override
        public void run() {
            synchronized (i){
                Thread thread = Thread.currentThread();
                System.out.println(thread.getName()+"--@"+System.identityHashCode(i));
                i++;
                System.out.println(thread.getName()+"-------[i="+i+"]-@"
                        +System.identityHashCode(i));
                SleepTools.ms(3000);
                System.out.println(thread.getName()+"-------[i="+i+"]--@"
                        +System.identityHashCode(i));
            }
        }
    }
}
